package com.bitbank.smartdevice.adapter.base

import android.graphics.Rect
import android.support.v7.widget.RecyclerView
import android.view.View

/**
 *  Date：2018/12/13
 *  Author：xulee
 *  Desc：
 */
class SpacesItemDecoration(innerSpace: Int, edgeSpace: Int) : RecyclerView.ItemDecoration() {

    private val halfInnerSpace: Int = innerSpace / 2
    private val halfEdgeSpace: Int = edgeSpace / 2

    override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {

        if (parent.paddingLeft != halfInnerSpace) {
            parent.setPadding(halfEdgeSpace, 0, halfEdgeSpace, halfEdgeSpace)
            parent.clipToPadding = false
        }

        outRect.top = halfInnerSpace
        if(parent.getChildLayoutPosition(view) == 0) {
            outRect.top = 0
        }

        outRect.bottom = halfInnerSpace
        outRect.left = halfInnerSpace
        outRect.right = halfInnerSpace
    }
}
